package com.xl.web.controller.zoom;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xl.base.annotation.Auth;
import com.xl.base.page.Page;
import com.xl.base.page.PageBean;
import com.xl.base.web.BaseController;
import com.xl.core.util.HtmlUtil;
import com.xl.web.entity.zoom.Dept;
import com.xl.web.service.zoom.DeptService;

@Controller
@RequestMapping("/dept")
public class DeptInfoController extends BaseController {
	@Autowired(required = false)
	private DeptService<Dept> deptService;
	@RequestMapping(value = "/queryPages",method=RequestMethod.GET)
	@ResponseBody
	@Auth(verifyLogin = false)
	/**
	 * 获取部门信息
	 * @param levelId
	 * levelId =all获取所有部门信息
	 * levelId 为其他值时，获取当前层级的部门信息
	 */
	public void queryPageDeptInfo(Dept dept,Page page)
			throws Exception {
		    //返回数据
		    Map<String,Object> result = new HashMap<String,Object>();		
		    PageBean  pageBean =	deptService.queryPageDeptInfo(dept, page);
		    result.put(this.SUCCESS, true);
		    result.put(this.MSG, "查询成功!");
		   // result.put("count", depts!=null?depts.size():0);
		    result.put("data",pageBean);
		    HtmlUtil.writerJson(response, result);			
	}
	
	@RequestMapping("/queryDept")
	@ResponseBody
	@Auth(verifyLogin = false)
	public void queryDeptInfo(Dept dept)
			throws Exception {
		    //返回数据
		    Map<String,Object> result = new HashMap<String,Object>();		
		    List<Dept> depts =	deptService.queryDeptInfo(dept);
		    result.put(this.SUCCESS, true);
		    result.put(this.MSG, "查询成功!");
		    result.put("count", depts!=null?depts.size():0);
		    result.put("data", depts);
		    HtmlUtil.writerJson(response, result);			
	}
	
	

	@RequestMapping(value="/queryDeptAndUser",method=RequestMethod.GET)
	@ResponseBody
	@Auth(verifyLogin = false)
	public void queryDeptAndUser(Dept dept)
			throws Exception {
		    //返回数据
		    Map<String,Object> result = new HashMap<String,Object>();		
		    List<Dept> depts =	deptService.queryDeptAndUser(dept);
		    result.put(this.SUCCESS, true);
		    result.put(this.MSG, "查询成功!");
		    result.put("count", depts!=null?depts.size():0);
		    result.put("data", depts);
		    HtmlUtil.writerJson(response, result);			
	}


}
